package org.dromara.oce.domain.dto;

import cn.hutool.core.util.NumberUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.dromara.oce.utils.PlatformParamTransUtil;

import java.math.BigDecimal;
import java.math.RoundingMode;

@Slf4j
@Data
public class GetOceEverydayCostCensusDataDTO {
    /**
     * 总消耗
     */
    private BigDecimal cost = BigDecimal.ZERO;
    /**
     * 当日总收入
     */
    private BigDecimal thatdayTotalAmount = BigDecimal.ZERO;
    /**
     * 当日总支付笔数
     */
    private Integer thatdayPaidTotalNum = 0;
    /**
     * 当日分成金额
     */
    private BigDecimal thatdayDividendAmount = BigDecimal.ZERO;
    /**
     * 当日注册用户的总收入
     */
    private BigDecimal thatdayRegisterTotalAmount = BigDecimal.ZERO;
    /**
     * 当日注册用户的分成金额
     */
    private BigDecimal thatdayRegisterDividendAmount = BigDecimal.ZERO;
    /**
     * 当日利润金额=当日分成金额-当日消耗
     */
    private BigDecimal thatdayProfitAmount = BigDecimal.ZERO;
    /**
     * 消耗时速
     */
    private BigDecimal costHoursSpeed = BigDecimal.ZERO;
    /**
     * 当日IAA总收入
     */
    private BigDecimal iaaTotalAmount = BigDecimal.ZERO;
    /**
     * 当日IAA分成金额
     */
    private BigDecimal iaaDividendAmount = BigDecimal.ZERO;
    /**
     * 当日注册用户的IAA总收入
     */
    private BigDecimal iaaRegisterTotalAmount = BigDecimal.ZERO;
    /**
     * 当日注册用户的IAA分成金额
     */
    private BigDecimal iaaRegisterDividendAmount = BigDecimal.ZERO;

    /**
     * 当日LTV
     */
    private BigDecimal attributionMicroGame0dLtv = BigDecimal.ZERO;

    /**
     * 当日广告变现ROI
     */
    private BigDecimal attributionMicroGame0dRoi = BigDecimal.ZERO;

    /**
     * 当日注册用户的利润金额
     */
    private BigDecimal thatdayRegisterProfitAmount = BigDecimal.ZERO;


    //商务当日分成金额
    private BigDecimal thatdayDividendAmountSw = BigDecimal.ZERO;
    //商务当日IAA分成金额
    private BigDecimal iaaDividendAmountSw = BigDecimal.ZERO;
    //商务当日利润金额
    private BigDecimal thatdayProfitAmountSw = BigDecimal.ZERO;


    /**
     * 回本率
     * IAP回本率 = 总分成金额 / 总消耗金额
     * IAA回本率=（总分成金额+广告总分成金额）/总消耗金额
     */
    private BigDecimal extRecoveryRate = BigDecimal.ZERO;

    /**
     * 新增回本率
     * 新增回本率 = （总新增分成金额+广告总新增分成金额）/总消耗金额
     */
    private BigDecimal extRegisterRecoveryRate = BigDecimal.ZERO;

    public void computeRecoveryRate(Integer referralLinkType) {
        try {
            BigDecimal costTemp = this.cost;
            if (NumberUtil.equals(this.cost, BigDecimal.ZERO)) {
                costTemp = new BigDecimal("1");
            }else{
//                costTemp = cost.divide(new BigDecimal("1.015"), 4, RoundingMode.HALF_UP);
            }
            if (PlatformParamTransUtil.isIapReferralType(referralLinkType)) {
                this.extRecoveryRate = this.thatdayTotalAmount.divide(costTemp, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).divide(BigDecimal.ONE, 2, RoundingMode.HALF_UP);
            } else if (PlatformParamTransUtil.isIaaReferralType(referralLinkType)) {
                this.extRecoveryRate = (this.iaaTotalAmount.add(this.thatdayTotalAmount)).divide(costTemp, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).divide(BigDecimal.ONE, 2, RoundingMode.HALF_UP);
            }
            if (PlatformParamTransUtil.isIapReferralType(referralLinkType)) {
                this.extRegisterRecoveryRate = this.thatdayRegisterTotalAmount.divide(costTemp, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).divide(BigDecimal.ONE, 2, RoundingMode.HALF_UP);
            } else if (PlatformParamTransUtil.isIaaReferralType(referralLinkType)) {
                this.extRegisterRecoveryRate = (this.iaaRegisterTotalAmount.add(this.thatdayRegisterTotalAmount)).divide(costTemp, 4, RoundingMode.HALF_UP).multiply(new BigDecimal("100")).divide(BigDecimal.ONE, 2, RoundingMode.HALF_UP);
            }
        } catch (Exception e) {
            System.out.println("回本率计算异常");
        }
    }

}
